package com.tk.exam.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;

/**
 * @author mrf
 * @Description:
 * @date 2019/06/18 上午10:44
 */
@Slf4j
public class JsonUtils {

    public static final <T> T string2Object(String json, Class<T> clazz) {

        if(org.apache.commons.lang3.StringUtils.isEmpty(json)){
            return null;
        }
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        try{
            gson.fromJson(json, clazz);
        }catch(Exception e){
            e.printStackTrace();
            log.info("入参错误"+e);
            return null;
        }
        return gson.fromJson(json, clazz);
    }

}
